<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<style>
    .hidden {
        display: none;
        /* 初始隐藏状态 */
        transition: display 0.5s ease-in-out;
        /* 注意：display的过渡效果并不总是有效，这里只是为了演示 */
    }

    .visible {
        display: block;
        /* 显示状态 */
        /* 可以添加一些动画效果 */
    }

    /* 如果需要动画效果，考虑使用opacity和visibility */
    .fade-in {
        opacity: 1;
        visibility: visible;
        transition: opacity 0.5s ease-in-out;
    }

    .fade-out {
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.5s ease-in-out;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            首件检测
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 工序" id="opCode" value="" disabled />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectOpCode()"></i>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="setUnQualified()">设置不合格</div>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr id="tr1"
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-family: 微软雅黑;font-size: 13px;font-weight: bold;">
                        <td algin='center'></td>
                        <td algin='center' style="display: none;">sysid</td>
                        <td algin='center'>条码</td>
                        <td algin='center'>工序</td>
                        <td algin='center'>状态</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
        <div id="myDiv" class="hidden">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-input" style="width:2%">
                            <input type="checkbox" name="quanxuan" id="quanxuan" value="" style='color:red'
                                onclick="allcheck()" />
                        </div>
                        <div class="aui-list-item-label" style="width:100%">全选</div>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <div style="height: 60px;"></div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var dqyxzCount = 0;
    var workCenterGid = ""; //仓库GID
    var workCenterCode = ""; //仓库编码
    var workCenterName = ""; //仓库名称


    var workCellGid = ""; //库位GID
    var workCellCode = ""; //库位编码
    var workCellName = ""; //库位名称

    //初始化
    apiready = function () {

        $("#opCode").focus();
        idSelector = "opCode";
    }
    function allcheck() {
        dqyxzCount = 0;
        var nn = $("#quanxuan").is(":checked"); //判断th中的checkbox是否被选中，如果被选中则nn为true，反之为false
        if (nn == true) {
            var namebox = $("input[name^='sub']");  //获取name值为boxs的所有input
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = true;    //js操作选中checkbox
            }
        }
        if (nn == false) {
            var namebox = $("input[name^='sub']");
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = false;
            }
        }

        //选中数据 
        // var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var check = $("input[id='allboxs']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        check.each(function () {
            dqyxzCount++;
        });

        $("#dqyxzNum").val(dqyxzCount);

    }

    //工序选择后回调函数
    function setOpCode(sysid, opCode, name) {
        document.getElementById('opCode').value = opCode;
        doSearch()
    }

    //6：选择工序
    function goSelectOpCode() {
        api.openWin({
            name: 'paOpCodeDaq',
            url: 'paOpCodeDaq.html',
            pageParam: {
                code: "",
                name: "firstArticleInspection",
            }
        });
    }

    //设置不合格
    function setUnQualified() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count == 0) {
            api.toast({
                msg: '请选择至少一条数据！',
                duration: 3000
            });
            return;
        }
        var list = [];
        var sysid = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            sysid = row.find("[name='sysid']").html();
            //if (sysid != "" || sysid != undefined || sysid != null) {
            list.push({
                sysid
            });
            // }
        });

        console.log(list)
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/setUnQualified";
        var data = {
            values: {
                list: list,
                un: un
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    $("input[name^='quanxuan']")[0].checked = false;
                    alert("保存成功")
                    //刷新数据
                    doSearch()
                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("连接超时，请耐心等待");
            }
        });
    }

    //查询
    function doSearch() {
        //获取设备唯一号
        var equipUniqueId = localStorage.getItem('equipUniqueId');
        var opCode = $("#opCode").val();
        if (opCode == "" || opCode == null || opCode == undefined) {
            api.toast({
                msg: '请选择工序！',
                duration: 3000
            });
            return
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchFAI";
        var data = {
            values: {
                opCode: opCode,
                un: un,
                epUniquecode: equipUniqueId
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td ><input name='sub' type='checkbox' id='allboxs' /></td>";
                        html += "<td name='sysid' style='display:none;' >" + list[i].sysid + "</td>";
                        html += "<td name='tm'  >" + list[i].produBarcode + "</td>";
                        html += "<td name='opCode'  >" + list[i].opCode + "</td>";
                        html += "<td name='state'  >" + list[i].checkFlag + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    var div = document.getElementById("myDiv");
                    if (div.classList.contains("visible") || div.classList.contains("fade-in")) {
                        //div是可见的
                    } else {
                        // 如果div是隐藏的，则显示它  
                        div.classList.remove("hidden", "fade-out");
                        div.classList.add("fade-in");
                        // 可以在动画开始前确保它是隐藏的，但在这个例子中我们已经在CSS中定义了  
                    }
                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("连接超时，请耐心等待");
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>